Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Output of following program?#include <stdi... Start Learning for Free
Output of following program?
#include <stdio.h>
int fun(int n, int *f_p)
{
    int t, f;
    if (n <= 1)
    {
        *f_p = 1;
        return 1;
    }
    t = fun(n- 1,f_p);
    f = t+ * f_p;
    *f_p = t;
    return f;
}
 
int main()
{
    int x = 15;
    printf (" %d n", fun(5, &x));
    return 0;
}
  • a)
    6
  • b)
    8
  • c)
    14
  • d)
    15
Correct answer is option 'B'. Can you explain this answer?
Verified Answer
Output of following program?#include <stdio.h>int fun(int n, int...
Let x is stored at location 2468 i.e. &x = 2468
(dots are use just to ensure alignment)
x = 15
fun(5, 2468)
...{t = fun(4, 2468)
.......{t = fun(3, 2468)
...........{t = fun(2,2468)
...............{t = fun(1, 2468)
...................{// x=1
........................return 1}
................t = 1
................f = 2 //1+1 //since *f_p is x
................x = t = 1
................return 2}
...........t = 2
...........f = 2+1
...........x = t = 2
...........return 3}
........t = 3
........f = 3+2
........x = t = 3
........return 5}
....t = 5
....f = 5+3
....x = t = 5
....return 8}
which implies fun (5,2468) is 8.
View all questions of this test
Most Upvoted Answer
Output of following program?#include <stdio.h>int fun(int n, int...
Let x is stored at location 2468 i.e. &x = 2468
(dots are use just to ensure alignment)
x = 15
fun(5, 2468)
...{t = fun(4, 2468)
.......{t = fun(3, 2468)
...........{t = fun(2,2468)
...............{t = fun(1, 2468)
...................{// x=1
........................return 1}
................t = 1
................f = 2 //1+1 //since *f_p is x
................x = t = 1
................return 2}
...........t = 2
...........f = 2+1
...........x = t = 2
...........return 3}
........t = 3
........f = 3+2
........x = t = 3
........return 5}
....t = 5
....f = 5+3
....x = t = 5
....return 8}
which implies fun (5,2468) is 8.
Free Test
Community Answer
Output of following program?#include <stdio.h>int fun(int n, int...
Explanation:

Function fun:
- The function `fun` takes two parameters, an integer `n` and a pointer to an integer `f_p`.
- It recursively calculates the value of `f` based on the formula `f(n) = f(n-1) + f(n-2)`.
- The base case for the recursion is when `n <= 1`,="" where="" it="" sets="" the="" value="" of="" `*f_p`="" to="" 1="" and="" returns="">
- The function then calculates `t` as the result of the recursive call with `n-1` and updates `f` based on the formula.
- Finally, it updates the value of `*f_p` to `t` and returns `f`.

Main function:
- In the `main` function, an integer `x` is initialized to 15.
- The `fun` function is called with parameters 5 and the address of `x`.
- The return value of the `fun` function is printed using `printf`.

Output:
- The function `fun(5, &x)` calculates the value of `f` for `n=5`.
- The recursive calls of the function lead to the following values of `f` - 1, 1, 2, 4, 7, 11.
- So, the final result returned by the function is 11.
- Therefore, the output of the program will be `11`.
Therefore, the correct answer is option 8.
Explore Courses for Computer Science Engineering (CSE) exam
Question Description
Output of following program?#include <stdio.h>int fun(int n, int *f_p){ int t, f; if (n <= 1) { *f_p = 1; return 1; } t = fun(n- 1,f_p); f = t+ * f_p; *f_p = t; return f;}int main(){ int x = 15; printf (" %d n", fun(5, &x)); return 0;}a)6b)8c)14d)15Correct answer is option 'B'. Can you explain this answer? for Computer Science Engineering (CSE) 2025 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Output of following program?#include <stdio.h>int fun(int n, int *f_p){ int t, f; if (n <= 1) { *f_p = 1; return 1; } t = fun(n- 1,f_p); f = t+ * f_p; *f_p = t; return f;}int main(){ int x = 15; printf (" %d n", fun(5, &x)); return 0;}a)6b)8c)14d)15Correct answer is option 'B'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2025 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Output of following program?#include <stdio.h>int fun(int n, int *f_p){ int t, f; if (n <= 1) { *f_p = 1; return 1; } t = fun(n- 1,f_p); f = t+ * f_p; *f_p = t; return f;}int main(){ int x = 15; printf (" %d n", fun(5, &x)); return 0;}a)6b)8c)14d)15Correct answer is option 'B'. Can you explain this answer?.
Solutions for Output of following program?#include <stdio.h>int fun(int n, int *f_p){ int t, f; if (n <= 1) { *f_p = 1; return 1; } t = fun(n- 1,f_p); f = t+ * f_p; *f_p = t; return f;}int main(){ int x = 15; printf (" %d n", fun(5, &x)); return 0;}a)6b)8c)14d)15Correct answer is option 'B'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of Output of following program?#include <stdio.h>int fun(int n, int *f_p){ int t, f; if (n <= 1) { *f_p = 1; return 1; } t = fun(n- 1,f_p); f = t+ * f_p; *f_p = t; return f;}int main(){ int x = 15; printf (" %d n", fun(5, &x)); return 0;}a)6b)8c)14d)15Correct answer is option 'B'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Output of following program?#include <stdio.h>int fun(int n, int *f_p){ int t, f; if (n <= 1) { *f_p = 1; return 1; } t = fun(n- 1,f_p); f = t+ * f_p; *f_p = t; return f;}int main(){ int x = 15; printf (" %d n", fun(5, &x)); return 0;}a)6b)8c)14d)15Correct answer is option 'B'. Can you explain this answer?, a detailed solution for Output of following program?#include <stdio.h>int fun(int n, int *f_p){ int t, f; if (n <= 1) { *f_p = 1; return 1; } t = fun(n- 1,f_p); f = t+ * f_p; *f_p = t; return f;}int main(){ int x = 15; printf (" %d n", fun(5, &x)); return 0;}a)6b)8c)14d)15Correct answer is option 'B'. Can you explain this answer? has been provided alongside types of Output of following program?#include <stdio.h>int fun(int n, int *f_p){ int t, f; if (n <= 1) { *f_p = 1; return 1; } t = fun(n- 1,f_p); f = t+ * f_p; *f_p = t; return f;}int main(){ int x = 15; printf (" %d n", fun(5, &x)); return 0;}a)6b)8c)14d)15Correct answer is option 'B'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Output of following program?#include <stdio.h>int fun(int n, int *f_p){ int t, f; if (n <= 1) { *f_p = 1; return 1; } t = fun(n- 1,f_p); f = t+ * f_p; *f_p = t; return f;}int main(){ int x = 15; printf (" %d n", fun(5, &x)); return 0;}a)6b)8c)14d)15Correct answer is option 'B'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam
Signup to solve all Doubts
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev